package com.quik.web.worker.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.quik.common.Constants;
import com.quik.entity.Room;
import com.quik.entity.DtaWorker;
import com.quik.entity.DtaWorkerType;
import com.quik.util.Tools;
import com.quik.web.base.mapper.PubSystemDao;
import com.quik.web.worker.mapper.WorkerDao;

/**
 * 功能说明：
 *         接口WorkerService的实现类
 * @author Jenny
 *
 */
@Service
public class WorkerServiceImpl implements WorkerService {
	
	@Autowired
	private WorkerDao dao;
	
	@Autowired
	private PubSystemDao systemDao;

	/**
	 * 根据条件查询技师类型数量
	 * @param workerTypeName
	 * @param printerNo
	 * @return
	 * @throws Exception
	 */
	@Override
	public int findWorkerTypeCount(String workerTypeName, Integer printerNo) throws Exception{
		int count = dao.findWorkerTypeCount(workerTypeName, printerNo);
		return count;
	}
	
	/**
	 * 根据条件查询技师类型列表（分页）
	 * @param workerTypeName
	 * @param printerNo
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<DtaWorkerType> findWorkerType(String workerTypeName, Integer printerNo, Integer intPage, Integer pageSize) throws Exception{
		List<DtaWorkerType> list = dao.findWorkerType(workerTypeName, printerNo, intPage, pageSize);
		return list;
	}
	
	/**
	 * 检查技师类型是否重命
	 * @param workerType
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean checkWorkerTypeName(String workerType) throws Exception{
		int count = dao.findWorkerTypeCountByTypeName(workerType);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增技师类型
	 * @param workerType
	 * @throws Exception
	 */
	@Override
	public void addWorkerType(DtaWorkerType workerType) throws Exception{
		dao.addWorkerType(workerType);
	}
	
	/**
	 * 查询技师状态
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findWorkerStatus() throws Exception{
		List list = systemDao.findSystemCodeBySection(Tools.getSection(DtaWorker.TABLE_NAME, Constants.SYSTEM_CODE_WORKERSTATUS));
		return list;
	}
	
	/**
	 * 根据条件查询技师数量
	 * @param workerNo
	 * @param workerName
	 * @param workerTypeId
	 * @param workerStatus
	 * @return
	 * @throws Exception
	 */
	@Override
	public int findWorkerCount(String workerNo, String workerName, Integer workerTypeId, String workerStatus) throws Exception{
		int count = dao.findWorkerCount(workerNo, workerName, workerTypeId, workerStatus);
		return count;
	}
	
	/**
	 * 根据条件查询技师列表（分页）
	 * @param workerNo
	 * @param workerName
	 * @param workerTypeId
	 * @param workerStatus
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findWorker(String workerNo, String workerName, Integer workerTypeId, String workerStatus, Integer intPage, Integer pageSize) throws  Exception{
		List list = dao.findWorker(workerNo, workerName, workerTypeId, workerStatus, intPage, pageSize);
		return list;
	}
	@Override
	public List<DtaWorker> findAllWorker() throws  Exception{
		return dao.findAllWorker();
	}
	
	/**
	 * 检查技师编号是否重复
	 * @param workerNo
	 * @return 若重复返回true, 否则返回false
	 * @throws Exception
	 */
	@Override
	public boolean checkWorkerNo(String workerNo) throws Exception{
		int count = dao.findWorkerCountByWorkerNo(workerNo);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增技师
	 * @param worker
	 * @throws Exception
	 */
	@Override
	public void addWorker(DtaWorker worker) throws Exception{
		dao.addWorker(worker);
	}
}
